﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using uTools;

public class LevelLoveRotate : MonoBehaviour
{
    public List<TextButton> tbList = new List<TextButton>();
    private List<string> wrongLoveList = new List<string>();
    public GameLevelItem gameLevelItem;
    public List<uTweenRotation> utrList = new List<uTweenRotation>();
    // Start is called before the first frame update
    void Start()
    {
        InitWrongLoveList();
        InitTextButton();
    }

    private void InitTextButton()
    {
        int count = tbList.Count;
        int rightIndex = Random.Range(0, count);
        for (int i = 0; i < count; i++)
        {
            if (i == rightIndex)
            {
                tbList[i].Init(UConst.Str_TargetLove, () =>
                {
                    gameLevelItem.TriggerResult(true);
                    StopRotate();
                });
            }
            else
            {
                tbList[i].Init(GetRandomWrongLove(), () =>
                {
                    gameLevelItem.TriggerResult(false);
                    StopRotate();
                });
            }
        }
    }

    private string GetRandomWrongLove()
    {
        string wrongLove = string.Empty;
        int count = wrongLoveList.Count;
        int randomIndex = Random.Range(0, count);
        wrongLove = wrongLoveList[randomIndex];
        wrongLoveList.RemoveAt(randomIndex);
        return wrongLove;
    }

    void InitWrongLoveList()
    {
        wrongLoveList.Add("lvoe");
        wrongLoveList.Add("lveo");
        wrongLoveList.Add("olve");
        wrongLoveList.Add("evol");
        wrongLoveList.Add("olev");
        wrongLoveList.Add("l0ve");
        wrongLoveList.Add("loue");
        wrongLoveList.Add("lone");
        wrongLoveList.Add("iove");
        wrongLoveList.Add("lovr");
        wrongLoveList.Add("lovv");
        wrongLoveList.Add("looe");
        wrongLoveList.Add("l0ue");
        wrongLoveList.Add("levo");
        wrongLoveList.Add("lveo");
        wrongLoveList.Add("loev");
        wrongLoveList.Add("levo");
        wrongLoveList.Add("vleo");
        wrongLoveList.Add("elvo");
    }

    private void StopRotate()
    {
        int count = utrList.Count;
        for (int i = 0; i < count; i++)
        {
            utrList[i].enabled = false;
        }
    }
}
